<?php
class groupApp extends core
{
	public function addAction($arg)
	{
		if (base::init('group')->insert($arg))
			$this->refresh('添加成功',"index.php?m=user&a=main#tabs-2");
	}
	
	public function deleteAction($arg)
	{
		if (isset($arg['ajax']))
		{
			$gid	= array('gid'=>explode(',',$arg['gid']));
			if (base::init('group')->delete($gid))
				print_r('1');
		}
	}

    public function editAction($arg)
    {
        if (isPost())
        {
            $edit   = array('class'=>join(',',$arg['class']),'article'=>join(',',$arg['article']),'data'=>join(',',$arg['data']),'classid'=>join(',',$arg['classid']),);
            $where  = array('gid'=>$arg['gid']);
            base::init('group')->edit($where, $edit);
			$this->refresh('修改成功',"index.php?m=user&a=main#tabs-2");
        }
        else
        {
            $template   = $this->template();
            $group      = base::init('group')->getRow(array('gid'=>$arg['gid']));
            $website    = base::init('website')->getRow(array('wid'=>$group['wid']));
            $columns    = base::init('column')->getAll(array('wid'=>$website['wid']));

            $template->assign('group', $group);
            $template->assign('website', $website);
            $template->assign('columns', $columns);
            $template->display('group_edit.php');
        }
    }
}
